package Chapter01.Homework;

import java.util.ArrayList;
import java.util.List;

//公司
public class Company implements Comparable<Employee>{
    private String name;
    private String address;
    private String telephone;
    private String scop;//经营范围
    List<Employee> list=new ArrayList<>();

    public void show(){
        System.out.println("公司名称"+name+",公司地址"+address+",电话"+telephone+",经营范围"+scop);
    }
    //添加员工
    public boolean add(Employee name){
        for (int i=0;i<list.size();i++){
            //员工号不能重复
            if(name.getId().equals(list.get(i).getId())){
                return false;
            }
        }
        list.add(name);
        return true;
    }
    //输出员工信息
    public void Message(){
        for (Object s:list){
            Employee n= (Employee) s;
            System.out.println(n);
        }
    }
    //公司人数
    public void people(){
        System.out.println(list.size());
    }
    //辞退员工
    public boolean resign(String id){
        for (Employee s:list){
            if(s.getId().equals(id)){
                list.remove(s);
                return true;
            }
        }
        return false;
    }
    //获得薪水最高的员工方法
    public Employee max(){
        Employee s=null;
        for (int i=0;i<list.size()-1;i++){
            for (int j=i+1;j<list.size();j++){
                if(list.get(i).getSalary()>list.get(j).getSalary()){
                    s=list.get(i);
                    return s;
                }
                return s;
            }
            return s;
        }
        return null;
    }

    public Company(String name, String address, String telephone, String scop) {
        this.name = name;
        this.address = address;
        this.telephone = telephone;
        this.scop = scop;
    }

    @Override
    public int compareTo(Employee o) {
        for (int i=0;i<list.size()-1;i++){
            for (int j=i+1;j<list.size();j++){
                if(list.get(i).getAge()>list.get(j).getAge()){
                    o=list.get(i);
                }
            }
            System.out.println(o);
            return 1;
        }
        return -1;
    }
}
